<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Login;
use app\admin\model\ConfigModel;
use app\admin\model\LinkModel;
use think\Request;
class Conf extends Admin
{
    // 加载网站基本信息页
    public function index()
    {
        $this->assign('title','FLY后台管理-网站设置');
        return view('Conf/index');
    }
    //加载修改密码页面
    public function pwd()
    {
    	$this->assign('title','FLY后台管理-修改密码');
    	return view('Conf/pwd');
    }
    //执行修改密码
    public function pwddo(){
        if(request()->isPost()){
            $res = (new Login())->pwd(input('post.'));
            if($res['valid'])
            {
                session('admin',null);
                //说明修改成功
                $this->success($res['msg']);
            }else{
                //说明修改失败
                $this->error($res['msg']);exit;
            }
        }
    }
    //网站设置1 
    public function setup1(){
        if(request()->isPost()){
            $res = (new ConfigModel())->setup1(input('post.'));
            if($res['valid'])
            {
                //说明修改成功
                $this->success($res['msg']);
            }else{
                //说明修改失败
                $this->error($res['msg']);exit;
            }
        }
    }
    //网站设置2
    public function setup2(){
        if(request()->isPost()){
            $res = (new ConfigModel())->setup2(input('post.'));
            if($res['valid'])
            {
                //说明修改成功
                $this->success($res['msg']);
            }else{
                //说明修改失败
                $this->error($res['msg']);exit;
            }
        }
    }
    //网站设置3
    public function setup3(){
        if(request()->isPost()){
            $res = (new ConfigModel())->setup3(input('post.'));
            if($res['valid'])
            {
                //说明修改成功
                $this->success($res['msg']);
            }else{
                //说明修改失败
                $this->error($res['msg']);exit;
            }
        }
    }
    //网站设置4
    public function setup4(){
        if(request()->isPost()){
            $res = (new ConfigModel())->setup4(input('post.'));
            if($res['valid'])
            {
                //说明修改成功
                $this->success($res['msg']);
            }else{
                //说明修改失败
                $this->error($res['msg']);exit;
            }
        }
    }
    //网站设置5
    public function setup5(){
        if(request()->isPost()){
            $res = (new ConfigModel())->setup5(input('post.'));
            if($res['valid'])
            {
                //说明修改成功
                $this->success($res['msg']);
            }else{
                //说明修改失败
                $this->error($res['msg']);exit;
            }
        }
    }
    //加载友情链接页面
    public function link()
    {
        $linkList = (new LinkModel())->linkList();
        // dump($linkList);die;
        $this->assign('linkList',$linkList);
        $this->assign('title','FLY后台管理-友情链接列表');
        return view('Conf/link');
    }
    // 加载友情链接添加页面
    public function linkAdd()
    {
        $this->assign('title','FLY后台管理-添加友链');
        return view('Conf/linkAdd');
    }

    // 执行友情链接执行操作
    public function linkAddDo()
    {
        if(request()->isPost()){
            $res = (new LinkModel())->add(input('post.'));
            if($res['valid'])
            {
                //说明修改成功
                $this->success($res['msg']);
            }else{
                //说明修改失败
                $this->error($res['msg']);exit;
            }
        }  
    }
    //执行友情链接删除操作
    public function linkDel()
    {
        if(request()->isGet()){
            $res = (new LinkModel())->del(input('id'));
            if($res['valid'])
            {
                //说明修改成功
                $this->success($res['msg']);
            }else{
                //说明修改失败
                $this->error($res['msg']);exit;
            }
        }  

    }
    //测试邮件配置
    public function public_test_mail()
    {
        $to_email = input('post.mail_to');
        $email_nickname = input('post.email_nickname');
        $data =array('mail_to' =>$to_email ,'email_name'=>$email_nickname );
        $subject = '测试';
        $message = '我是测试邮件';
        $res = send_email($data['mail_to'], $subject, $message, $data['email_name']);
        return json($res);
    }
}
